home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Telnet 2.7b5 / source / main / menuseg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-28  |  45.6 KB  |  1,684 lines  |  [TEXT/CWIE]

  1. /****************************************************************
  2. *    NCSA Telnet for the Macintosh                                *
  3. *                                                                *
  4. *    National Center for Supercomputing Applications                *
  5. *    Software Development Group                                    *
  6. *    152 Computing Applications Building                            *
  7. *    605 E. Springfield Ave.                                        *
  8. *    Champaign, IL  61820                                        *
  9. *                                                                *
  10. *    Copyright (c) 1986-1992,                                    *
  11. *    Board of Trustees of the University of Illinois                *
  12. *****************************************************************
  13. *
  14. *    Menu Handling and initialization code.
  15. *
  16. *    
  17. *    Revisions:
  18. *    7/92 Telnet 2.6 initial version: reorganized defines, put all stray globals in a struct, and
  19. *                put all cursors in a nice array.  Moved some routines to other places -    Scott Bulmahn            
  20. *
  21. *    6/94 Added support for Keypad and Function menus - Carl Bell (Baylor U.)
  22. */
  23.  
  24. #ifdef MPW
  25. #pragma segment 4
  26. #endif
  27.  
  28.  
  29. #include "wind.h"
  30. #include "menuseg.proto.h"
  31. #include "mainseg.proto.h"
  32. #include "Sets.proto.h"                /* JMB: For Saved Sets functions */
  33. #include "configure.proto.h"
  34. #include "parse.proto.h"
  35. #include "InternalEvents.h"
  36. #include "mydnr.proto.h"
  37. #include "rsinterf.proto.h"
  38. #include "network.proto.h"
  39. #include "maclook.proto.h"
  40. #include "vrrgmac.proto.h"
  41. #include "rgmp.proto.h"
  42. #include "tekrgmac.proto.h"
  43. #include "vgtek.proto.h"
  44. #include "netevent.proto.h"
  45. #include "Connections.proto.h"
  46. #include "tnae.h"
  47. #include "authencrypt.proto.h"
  48. #include "vsdata.h"
  49. #include "vsinterf.proto.h"
  50.  
  51. #include "event.proto.h"
  52. #include "macros.proto.h"
  53. #include "DlogUtils.proto.h"            /* For VersionNumber, OutlineItem, and DialogProc Protos */
  54. #include "telneterrors.h"
  55.  
  56.  
  57. #include <Printing.h>
  58. #include "printing.proto.h"
  59. #include "menuseg.proto.h"
  60. #include "translate.proto.h"
  61. #include "parse.proto.h"                // For SendNAWSinfo proto
  62. #include "keypadmenus.proto.h"
  63. #include "LinkedList.proto.h"
  64. MenuHandle
  65.     myMenus[NMENUS];        /* Menu Handles .... */
  66. static short lastMenyCommandKeys = -1; //whether last menu set had command keys
  67.  
  68. //char *tempspot;                /* temporary storage ~255 bytes malloc-ed */
  69.  
  70.  
  71. /*
  72.  * External variable declarations (those which we borrow )
  73.  *
  74.  */
  75. extern short scrn;
  76. extern Cursor *theCursors[];
  77. extern WindRec
  78.     *screens,            /* The screen array from Maclook */
  79.     *ftplog;                    /* The FTP log screen from Maclook */
  80. extern    short    nNational;
  81.  
  82. void CloseCaptureFile(short w)
  83. {
  84.     VSclosecapture(w);                                /* BYU 2.4.18 */
  85.     CheckItem(myMenus[Emul], EMcapture,FALSE);        /* BYU 2.4.18 */
  86. }
  87.  
  88. /*    portsOpen()    - Count the number of ports open. Returns 3 different answers
  89.  *                  0= no ports at all, 1= at least active, -1= ports/none active. */
  90. short    portsOpen(void)
  91. {
  92.     short pnum;
  93.  
  94.     pnum=TelInfo->numwindows-1;
  95.     if (pnum<0)  return(0);
  96.     while (pnum>=0) 
  97. //        if (!screens[pnum--].active && !screens[pnum+1].corpse) return(1);
  98.         // corpse status now part of active flag
  99.         if (screens[pnum--].active == CNXN_ACTIVE) return(1);
  100.     return(-1);
  101. }
  102.  
  103. void switchToOptionMenus(Boolean useOptionedStuff)
  104. {
  105.      Str255 theMenuItem;
  106.      short whichString;
  107.      if (useOptionedStuff)
  108.          whichString = CLOSE_ALL_MENU_ITEM;
  109.      else
  110.          whichString = CLOSE_MENU_ITEM;
  111.     
  112.      GetIndString(theMenuItem,MISC_STRINGS,whichString);
  113.     
  114.      SetItem(myMenus[Fil],FLclose,theMenuItem);
  115. }
  116.  
  117. void switchToShiftMenus(Boolean useShiftStuff)
  118. {
  119.      Str255 theMenuItem;
  120.      short whichString;
  121.      if (useShiftStuff)
  122.          whichString = PREVIOUS_SESSION_STRING;
  123.      else
  124.          whichString = NEXT_SESSION_STRING;
  125.     
  126.      GetIndString(theMenuItem,MISC_STRINGS,whichString);
  127.      SetItem(myMenus[Conn],COnext,theMenuItem);
  128.          
  129. }
  130. void    AdjustMenus(void)
  131. {
  132.     short        i;
  133.     WindowPtr    wind;
  134.     
  135.     if ((wind = FrontWindow()) != NULL && (((WindowPeek)wind)->windowKind >= userKind))
  136.         EnableItem( myMenus[Fil],FLclose);
  137.     else
  138.         DisableItem( myMenus[Fil],FLclose);
  139.         
  140.     if ((i=portsOpen()) <1) {
  141.         DisableItem( myMenus[Fil],FLsave);
  142.         DisableItem( myMenus[Fil],FLprint);
  143.         DisableItem( myMenus[Edit],EDcut);
  144.         DisableItem( myMenus[Edit],EDundo);
  145.         DisableItem( myMenus[Edit],EDclear);
  146.         DisableItem( myMenus[Edit],EDcopy);
  147.         DisableItem( myMenus[Edit],EDcopyt);
  148.  
  149.  
  150.         DisableItem( myMenus[Emul],EMbs);
  151.         DisableItem( myMenus[Emul],EMdel);
  152.         DisableItem( myMenus[Emul],EMecho);
  153.         DisableItem( myMenus[Emul],EMwrap);
  154.         DisableItem( myMenus[Emul],EMscroll);
  155.         DisableItem( myMenus[Emul],EMreset);
  156.         DisableItem ( myMenus[Emul],EMjump);
  157.         DisableItem ( myMenus[Emul],EMpage);
  158.         DisableItem ( myMenus[Emul],EMclear);    /* BYU 2.4.14 */
  159.         DisableItem ( myMenus[Emul],EMscreensize);
  160.         DisableItem ( myMenus[Emul],EMsetup);
  161.         DisableItem ( myMenus[Emul],EMfont);
  162.         DisableItem ( myMenus[Emul],EMsize);
  163.         DisableItem ( myMenus[Emul],EMcolor);
  164.         DisableItem ( myMenus[Emul],EMAnsiColor);
  165.         DisableItem ( myMenus[Emul],EMcapture);    /* BYU 2.4.18 */
  166.  
  167.         DisableItem( myMenus[Net ],NEftp);
  168.         DisableItem( myMenus[Net ],NEip);
  169.         DisableItem( myMenus[Net ],NEayt);
  170.         DisableItem( myMenus[Net ],NEao);
  171.         DisableItem( myMenus[Net ],NEinter);
  172.         DisableItem( myMenus[Net ],NEec);
  173.         DisableItem( myMenus[Net ],NEel);
  174.         DisableItem( myMenus[Net ],NEscroll);
  175.  
  176.         if (TelInfo->ScrlLock) {
  177.             TelInfo->ScrlLock=0;
  178.             CheckItem(myMenus[Net ], NEscroll,FALSE);
  179.             }
  180.         }
  181.     else {
  182.         EnableItem ( myMenus[Fil],FLsave);
  183.         EnableItem ( myMenus[Emul],EMbs);
  184.         EnableItem ( myMenus[Emul],EMdel);
  185.         EnableItem ( myMenus[Emul],EMecho);
  186.         EnableItem ( myMenus[Emul],EMwrap);
  187.         if (nNational > 0) {
  188.             EnableItem ( myMenus[National], 0);
  189.             }
  190.         EnableItem ( myMenus[Emul],EMscroll);
  191.         EnableItem ( myMenus[Emul],EMreset);
  192.         EnableItem ( myMenus[Emul],EMjump);
  193.         EnableItem ( myMenus[Emul],EMpage);
  194.         EnableItem ( myMenus[Emul],EMclear);    /* BYU 2.4.14 */
  195.         EnableItem ( myMenus[Emul],EMscreensize);
  196.         EnableItem ( myMenus[Emul],EMsetup);
  197.         EnableItem ( myMenus[Emul],EMfont);
  198.         EnableItem ( myMenus[Emul],EMsize);
  199.         EnableItem ( myMenus[Emul],EMcapture);    /* BYU 2.4.18 */
  200.     
  201.         if (TelInfo->haveColorQuickDraw) 
  202.         {
  203.             EnableItem ( myMenus[Emul],EMcolor);
  204.             EnableItem ( myMenus[Emul],EMAnsiColor);
  205.         }
  206.         EnableItem ( myMenus[Net ],NEftp);
  207.         EnableItem ( myMenus[Net ],NEip);
  208.         EnableItem ( myMenus[Net ],NEayt);
  209.         EnableItem ( myMenus[Net ],NEao);
  210.         EnableItem ( myMenus[Net ],NEinter);
  211.         EnableItem ( myMenus[Net ],NEec);
  212.         EnableItem ( myMenus[Net ],NEel);
  213.         EnableItem ( myMenus[Net ],NEscroll);
  214.     }
  215.  
  216. }
  217.  
  218. /*    switchMenus( which) - Switch from our current menus to the key menus (1)
  219.  *                          or the normal menus (0). */
  220. void switchMenus(short which)
  221. {
  222.     short i;
  223.         
  224.     if (lastMenyCommandKeys != which)
  225.     {
  226.         lastMenyCommandKeys = which;
  227.         DeleteMenu( fileMenu);                    /* Take them from the menu bar */
  228.         DeleteMenu( editMenu);
  229.         DeleteMenu( termMenu);
  230.         DeleteMenu(  netMenu);
  231.         DeleteMenu(  keyMenu);                /* Baylor */
  232.         DeleteMenu( funcMenu);                /* Baylor */
  233.         DeleteMenu(NfileMenu);                
  234.         DeleteMenu(NeditMenu);
  235.         DeleteMenu(NtermMenu);
  236.         DeleteMenu(NnetMenu);
  237.  
  238.         if (which) 
  239.         {
  240.             myMenus[Fil ] = GetMenu(NfileMenu);
  241.             myMenus[Edit] = GetMenu(NeditMenu);
  242.             myMenus[Emul] = GetMenu(NtermMenu);
  243.             myMenus[Net ] = GetMenu(NnetMenu );
  244.             myMenus[Keypad] = GetMenu(keyMenu);            /* Baylor */
  245.             myMenus[Function] = GetMenu(funcMenu);        /* Baylor */
  246.     
  247.             DelMenuItem(myMenus[Conn],COnext);
  248.             InsMenuItem(myMenus[Conn],(StringPtr)"\017Next Session/N\0",0);
  249.             }
  250.         else 
  251.         {
  252.             myMenus[Fil ] = GetMenu(fileMenu);
  253.             myMenus[Edit] = GetMenu(editMenu);
  254.             myMenus[Emul] = GetMenu(termMenu);
  255.             myMenus[Net ] = GetMenu( netMenu);
  256.             myMenus[Keypad] = GetMenu(keyMenu);            /* Baylor */
  257.             myMenus[Function] = GetMenu(funcMenu);        /* Baylor */
  258.     
  259.             DelMenuItem(myMenus[Conn],COnext);
  260.             InsMenuItem(myMenus[Conn],(StringPtr)"\015Next Session\0",0);
  261.         }
  262.     }
  263.     for(i=1; i<Conn; i++)
  264.         InsertMenu( myMenus[i], connMenu);    /* Put them in the menu bar */
  265.  
  266.     if (gApplicationPrefs->KeyPadAndFuncMenus) {            /* Baylor */
  267.         InsertMenu(myMenus[Keypad], 0);                        /* Baylor */
  268.         InsertMenu(myMenus[Function], 0);                    /* Baylor */
  269.         }
  270.  
  271.     AdjustMenus();            /* Hilite the right stuff */
  272.  
  273.     if (TelInfo->MacBinary)
  274.         CheckItem(myMenus[Fil],FLbin,TRUE);        /* Check MacBinary ... */
  275.     else
  276.         CheckItem(myMenus[Fil],FLbin,FALSE);
  277.  
  278.     if (TelInfo->ftplogon)
  279.         CheckItem(myMenus[Fil],FLlog,TRUE);        /* and the log .... */
  280.     else
  281.         CheckItem(myMenus[Fil],FLlog,FALSE);
  282.  
  283.     if (TelInfo->ScrlLock)                                 /* and the Suspend network ... */
  284.         CheckItem(myMenus[Net], NEscroll,TRUE);
  285.     else 
  286.         CheckItem(myMenus[Net], NEscroll,FALSE);
  287.  
  288.     if (TelInfo->numwindows>0)                            /* and set the BSDEL flag */
  289.         CheckItem(myMenus[Emul], EMbs+screens[scrn].bsdel,FALSE);
  290.  
  291.     DrawMenuBar();                                /* Draw what we have done */
  292.  
  293.     SetupOpSpecSubmenu(myMenus[OpSpec]);
  294.  
  295.     if (!TelInfo->haveColorQuickDraw)
  296.         DisableItem( myMenus[Emul], EMcolor);
  297.  
  298. }
  299.  
  300. /*    setupmenu - Set up (load) all menus and prepare menu bar.
  301.  *                set default check marks. */
  302. void setupmenu(short def)
  303. {
  304.     lastMenyCommandKeys = def;
  305.     myMenus[0] = GetMenu(appleMenu);                /* Get all of our friendly menus */
  306.     myMenus[Conn] = GetMenu(connMenu);
  307.     myMenus[Font] = GetMenu(fontMenu);
  308.     myMenus[Sizem] = GetMenu(sizeMenu);
  309.     myMenus[OpSpec] = GetMenu(opspecMenu);
  310.     myMenus[PrefsSub] = GetMenu(prefsMenu);
  311.     myMenus[National] = GetMenu(transMenu);
  312.     myMenus[Keypad] = GetMenu(keyMenu);            /* Baylor */
  313.     myMenus[Function] = GetMenu(funcMenu);        /* Baylor */
  314.     myMenus[Fil ] = GetMenu(NfileMenu);
  315.     myMenus[Edit] = GetMenu(NeditMenu);
  316.     myMenus[Emul] = GetMenu(NtermMenu);
  317.     myMenus[Net ] = GetMenu(NnetMenu );
  318.  
  319.     AddResMenu(myMenus[0], 'DRVR');                    /* Add in the DA's */
  320.  
  321.     InsertMenu(myMenus[0], 0);                        /* Insert the Menus into the bar */
  322.     InsertMenu(myMenus[Conn], 0);
  323.     if (gApplicationPrefs->KeyPadAndFuncMenus) {    /* Baylor */
  324.         InsertMenu(myMenus[Keypad], 0);                /* Baylor */
  325.         InsertMenu(myMenus[Function], 0);            /* Baylor */
  326.         }
  327.     InsertMenu(myMenus[Font], -1);
  328.     InsertMenu(myMenus[Sizem], -1);
  329.     InsertMenu(myMenus[OpSpec], -1);
  330.     InsertMenu(myMenus[National], -1);
  331.     InsertMenu(myMenus[PrefsSub], -1);
  332.     
  333.     addMonoSpacedFonts(myMenus[Font]);
  334.     SetupOpSpecSubmenu(myMenus[OpSpec]);
  335.     switchMenus(def);
  336.  
  337. }
  338.  
  339. void addMonoSpacedFonts(MenuHandle theMenu)
  340. {
  341.     Boolean doItAll = FALSE;
  342.     Handle    theGoodFonts, theBadFonts;
  343.     short    numGoodFonts, numBadFonts,numFontsInMenu;
  344.     short menuIndex;
  345.     Str255 fontListName,currentFontName;
  346.     
  347.     //here begins the caching of fonts to save time caculating proportionality
  348.     UseResFile(TelInfo->SettingsFile);
  349.     
  350.     theGoodFonts = Get1Resource('STR#',4000); //the good fonts
  351.     if (!theGoodFonts)
  352.     {
  353.         UseResFile(TelInfo->ApplicationFile);
  354.         theGoodFonts = Get1Resource('STR#',4000);
  355.         theBadFonts = Get1Resource('STR#',5000);
  356.         DetachResource(theGoodFonts);
  357.         DetachResource(theBadFonts);
  358.         UseResFile(TelInfo->SettingsFile);
  359.         AddResource(theGoodFonts,'STR#',4000,"\pGood Fonts");
  360.         AddResource(theBadFonts,'STR#',5000,"\pBad Fonts");
  361.     }
  362.     else
  363.         theBadFonts = Get1Resource('STR#',5000);
  364.  
  365. redoTheList:            
  366.  
  367.     numGoodFonts = *(short *)(*theGoodFonts);
  368.     if (numGoodFonts == 0)
  369.         doItAll = TRUE; //we haven't created a list of fonts yet
  370.     else
  371.         numBadFonts = *(short *)(*theBadFonts);
  372.  
  373.     AddResMenu(theMenu,'FONT'); //add them all here
  374.     numFontsInMenu = CountMItems(theMenu);
  375.     if (numFontsInMenu != (numBadFonts + numGoodFonts))
  376.     {
  377.         SetHandleSize(theGoodFonts,2);
  378.         *((short *)*theGoodFonts) = 0; 
  379.         SetHandleSize(theBadFonts,2);
  380.         *((short *)*theBadFonts) = 0; 
  381.         doItAll = TRUE;
  382.     }
  383.     if (!doItAll) //we have a list already
  384.     {
  385.         short goodFontIndex, badFontIndex;
  386.         goodFontIndex = badFontIndex = 1;
  387.         
  388.         for (menuIndex = 1; menuIndex <=  numFontsInMenu; menuIndex++)
  389.         {    //look at each font, see if its bad, good, or new
  390.             GetItem(theMenu,menuIndex,currentFontName);
  391.             GetIndString(fontListName,5000,badFontIndex);
  392.             if (EqualString(currentFontName,fontListName,TRUE,FALSE))
  393.             {
  394.                 DelMenuItem(theMenu,menuIndex); //remove the bad font from the menu
  395.                 numFontsInMenu--; 
  396.                 menuIndex--;
  397.                 badFontIndex++;
  398.             }
  399.             else
  400.             {    
  401.                 GetIndString(fontListName,4000,goodFontIndex);
  402.                 if (EqualString(currentFontName,fontListName,TRUE,FALSE))
  403.                     goodFontIndex++;
  404.                 else //its a new font, and we didn't expect it; this means there were an equal
  405.                 {    //number of fonts removed and added.  Lets start over. 
  406.                     short numberInMenu;
  407.                     numberInMenu = CountMItems(theMenu);
  408.                     for (;numberInMenu > 0; numberInMenu--)
  409.                         DelMenuItem(theMenu,numberInMenu);//clear the menu
  410.                     SetHandleSize(theGoodFonts,2);//clear the lists
  411.                     SetHandleSize(theBadFonts,2);
  412.                     
  413.                     goto redoTheList;
  414.                 }
  415.             }
  416.         }
  417.     }        
  418.     else //create a new list
  419.     {
  420.         DialogPtr     dtemp;
  421.         dtemp = GetNewMyDialog(130, NULL, kInFront, (void *)SecondThirdCenterDialog);    /* opening dialog */
  422.         DrawDialog(dtemp);
  423.         
  424.                                             
  425.         for (menuIndex = 1; menuIndex <=  numFontsInMenu; menuIndex++)
  426.         {
  427.             GetItem(theMenu,menuIndex,currentFontName);
  428.             if (!isMonospacedFont(currentFontName))
  429.             {
  430.                 DelMenuItem(theMenu,menuIndex); //remove the bad font from the menu
  431.                 numFontsInMenu--; 
  432.                 menuIndex--;
  433.                 PtrAndHand(currentFontName,theBadFonts,currentFontName[0]+1);//add it to the bad list
  434.                 (*(short *)(*theBadFonts))++;
  435.             }
  436.             else
  437.             {
  438.                 PtrAndHand(currentFontName,theGoodFonts,currentFontName[0]+1);//add it to the good list
  439.                 (*(short *)(*theGoodFonts))++;
  440.             }
  441.         }
  442.         DisposDialog(dtemp);    
  443.     }    
  444.     ChangedResource(theGoodFonts);
  445.     ChangedResource(theBadFonts);
  446.     ReleaseResource(theGoodFonts);
  447.     ReleaseResource(theBadFonts);
  448.     UpdateResFile(TelInfo->SettingsFile);
  449. }
  450.  
  451. Boolean isMonospacedFont(Str255 theFont)
  452. {
  453.     Boolean haveNonRomanScripts,thisOneIsMonospaced = FALSE, doRomanTest = FALSE;
  454.     short fond;
  455.     long tempLong;
  456.     //GrafPtr tempPort, savedPort;
  457.  
  458.     //first, open a temporary port to test CharWidth
  459.     //tempPort = (GrafPtr)myNewPtrCritical(sizeof(GrafPort));
  460.     //GetPort(&savedPort);
  461.     //OpenPort(tempPort);
  462.  
  463.     tempLong = GetScriptManagerVariable(smEnabled);    //this returns number of scripts enable
  464.     haveNonRomanScripts = (tempLong > 1); //if there is one, its roman
  465.     GetFNum(theFont,&fond);
  466.     if (haveNonRomanScripts)
  467.     {
  468.         long thisScriptEnabled;
  469.         ScriptCode scriptNumber;
  470.         
  471.         scriptNumber = FontToScript(fond);
  472.         if (scriptNumber != 0) //if its non-roman
  473.         {
  474.             thisScriptEnabled = GetScriptVariable(scriptNumber,smScriptEnabled);
  475.             if (thisScriptEnabled)
  476.             {
  477.                 //check if this font is the preferred monospaced font for its script
  478.                 long theSizeAndFond;
  479.                 short thePreferredFond;
  480.                 
  481.                 theSizeAndFond = GetScriptVariable(scriptNumber, smScriptMonoFondSize);
  482.                 thePreferredFond = theSizeAndFond >> 16; //high word is fond 
  483.                 thisOneIsMonospaced = (thePreferredFond == fond);
  484.             }
  485.             else
  486.                 thisOneIsMonospaced = FALSE; //this font's script isn't enabled
  487.         }
  488.         else
  489.             doRomanTest = TRUE;
  490.     }
  491.     else
  492.         doRomanTest = TRUE;
  493.         
  494.     if (doRomanTest)
  495.     {
  496.         TextFont(fond);
  497.         thisOneIsMonospaced = (CharWidth('W') == CharWidth('.'));
  498.     }
  499.     //SetPort(savedPort);
  500.     //ClosePort(tempPort);
  501.     //DisposePtr((Ptr)tempPort);
  502.     return(thisOneIsMonospaced);
  503.  
  504. void CheckOpSpecSubmenu(void)
  505. {
  506.     short numItems;
  507.     UseResFile(TelInfo->SettingsFile);
  508.     numItems = Count1Resources(SESSIONPREFS_RESTYPE);
  509.     if (CountMItems(myMenus[OpSpec]) != numItems)
  510.         SetupOpSpecSubmenu(myMenus[OpSpec]);
  511. }
  512.  
  513. void SetupOpSpecSubmenu(MenuHandle theMenu)
  514. {
  515.     short            scratchshort,numberofitems;
  516.     LinkedListNode    *theHead;    
  517.     scratchshort = CountMItems(theMenu);
  518.     for (; scratchshort>0; scratchshort--) DelMenuItem(theMenu, scratchshort);
  519.     
  520.     UseResFile(TelInfo->SettingsFile);
  521.     numberofitems = Count1Resources(SESSIONPREFS_RESTYPE);
  522.     if (numberofitems)
  523.     {    
  524.         theHead = createSortedList(SESSIONPREFS_RESTYPE,numberofitems,"\p<Default>"); //now we have a sorted linked list of the names
  525.         addListToMenu(theMenu,theHead);
  526.         deleteList(&theHead);
  527.     }
  528. }
  529.  
  530. /*    updateMenuChecks() - update the check marks for file transfer
  531.  *                         (MacBinary) */
  532.  
  533. void updateMenuChecks( void)
  534. {
  535.     if (TelInfo->MacBinary)
  536.         CheckItem(myMenus[Fil],FLbin,TRUE);        /* Check MacBinary ... */
  537.     else
  538.         CheckItem(myMenus[Fil],FLbin,FALSE);
  539. }
  540.  
  541. /*    DisplayMacBinary()    - Sets the macbinary check mark according to the MacBinary flag */
  542. void DisplayMacBinary( void)
  543. {
  544.     if (TelInfo->MacBinary)
  545.         CheckItem(myMenus[Fil],FLbin,TRUE);        /* Check MacBinary ... */
  546.     else
  547.         CheckItem(myMenus[Fil],FLbin,FALSE);
  548. }
  549.  
  550. /*CheckFonts()        - Place checkmarks and outlines on the appropriate
  551.  *                          menu items for the fonts */
  552. void CheckFonts(void)
  553. {
  554.     short     i, fsiz, fnum;
  555.     long    itemFontSize;
  556.     Str255     temp, itemString;
  557.  
  558.     RSgetfont( screens[scrn].vs, &fnum, &fsiz);
  559.     GetFontName(fnum, temp);
  560.     
  561.     for(i=1; i<= CountMItems( myMenus[Font]); i++)
  562.         {
  563.         GetItem( myMenus[Font], i, itemString);
  564.         if (EqualString(temp, itemString, FALSE, FALSE))
  565.             CheckItem( myMenus[Font], i, TRUE);            /* Check the current font */
  566.         else
  567.             CheckItem( myMenus[Font], i, FALSE);
  568.         }
  569.     
  570.     for(i=1; i<=CountMItems( myMenus[Sizem]); i++) {
  571.         GetItem( myMenus[Sizem], i, itemString);            /* JMB 2.6 -- Much safer to do it */
  572.         StringToNum(itemString, &itemFontSize);            /*                this way! */
  573.  
  574.         if (fsiz == (short)itemFontSize)
  575.             CheckItem( myMenus[Sizem], i, TRUE);            /* Check Our Current Size */
  576.         else
  577.             CheckItem( myMenus[Sizem], i, FALSE);
  578.  
  579.         if (RealFont( fnum, (short)itemFontSize))        /* Outline All Available REAL Sizes */
  580.             SetItemStyle( myMenus[Sizem], i, outline);
  581.         else
  582.             SetItemStyle( myMenus[Sizem], i, 0);
  583.         }
  584. }
  585.  
  586. /*    applAbout - display the about dialog for the application.*/
  587. void applAbout( void)
  588. {
  589.     DialogPtr About;
  590.     short itemhit;
  591.  
  592.     About=GetNewMyDialog( AboutDLOG, (Ptr) 0L,(WindowPtr) -1L, (void *)ThirdCenterDialog);
  593.     if (About) {
  594.         UItemAssign( About, 2, VersionNumberUPP);
  595.         ModalDialog(NULL, &itemhit);
  596.         DisposDialog(About);
  597.         }
  598. }
  599.  
  600. short ReallyClose( short scrn)
  601. {
  602.     DialogPtr    dtemp;
  603.     short        item;
  604.     Str255        scratchPstring;
  605.     
  606.     SetCursor(theCursors[normcurs]);
  607.  
  608.     GetWTitle(screens[scrn].wind, scratchPstring);
  609.     ParamText(scratchPstring, NULL, NULL, NULL);
  610.     
  611.     dtemp = GetNewMyDialog( CloseDLOG, NULL, kInFront, (void *)ThirdCenterDialog);
  612.  
  613.     item = DLOGCancel +1;
  614.     while (item> DLOGCancel)
  615.         ModalDialog(DLOGwOK_CancelUPP, &item);
  616.  
  617.     DisposDialog( dtemp);
  618.  
  619.     updateCursor(1);
  620.     
  621.     if (item == DLOGCancel) return(0);
  622.  
  623.     return(1);
  624. }
  625.  
  626. PicHandle RGtoPICT(short i)
  627. {
  628.     short j;
  629.     PicHandle tpic;
  630.     Rect trect;
  631.  
  632.     SetRect(&trect,0,0,384,384);
  633.     j=VGnewwin(TEK_DEVICE_PICTURE,VGgetVS(i));            /* NCSA 2.5: get the right VS */
  634.     RGMPsize( &trect );
  635.     VGzcpy( i, j);                /* Love dat zm factr */
  636.     tpic=OpenPicture(&trect);
  637.     ClipRect(&trect);
  638.     
  639.     VGredraw(i,j);
  640.     ClosePicture();
  641.     VGclose(j);
  642.  
  643.     return(tpic);
  644. }
  645.  
  646. /* 
  647.  * copyGraph    - Copy the current graphics screen.
  648.  *            dnum - the number of the drawing to copy .
  649.  */
  650. void copyGraph( short dnum)
  651. {
  652.     long tlong;                    /* Temporary Variable */
  653.     PicHandle tpic;                /* Mental picture of the thing */
  654.  
  655.     tpic=RGtoPICT(dnum);            /* Get the picture */
  656.     tlong=ZeroScrap();                /* Nobody else can live here */
  657.     HLock((Handle) tpic);                    /* Lock it for Puting */
  658.     tlong=PutScrap(GetHandleSize((Handle) tpic),'PICT', (Ptr) *tpic);    /* Store as a PICT */
  659.     HUnlock((Handle) tpic);                    /* Unlock so we can toss it */
  660.     KillPicture(tpic);                /* Kill the picture..... */
  661. }                
  662.  
  663. /* 
  664.  * copyText    - Copy the current selection on the virtual screen
  665.  *            vs - the number of the virtual screen to copy from
  666.  */
  667.  
  668. void copyText( short vs)
  669. {
  670.     char **charh;            /* where to store the characters */
  671.     long tlong;                /* Necessary temporary variable */
  672.  
  673.     tlong=ZeroScrap();        /* This Scrap aint big enough for the both of us */
  674.  
  675.     charh=RSGetTextSel(vs,0);        /* Get the text selection */
  676.  
  677.     if (charh == (char **)-1L)
  678.         OutOfMemory(400);
  679.     else if (charh != (char **)0L) {    /* BYU LSC - Can't do anything without characters */
  680.         HLock(charh);                /* Lock for putting */
  681.         tlong=PutScrap(GetHandleSize(charh),'TEXT',*charh);
  682.                                     /* Put it as a TEXT resource */
  683.         HUnlock(charh);                /* Unlock for disposal */
  684.         DisposHandle(charh);        /* Kill the chars */
  685.         }
  686. }
  687.  
  688. /* 
  689.  * copyTable   - Copy the current selection on the virtual screen
  690.  *            vs - the number of the virtual screen to copy from
  691.  */
  692.  
  693. void copyTable( short vs)
  694. {
  695.     char **charh;            /* where to store the characters */
  696.     long tlong;                /* Necessary temporary variable */
  697.  
  698.     tlong=ZeroScrap();        /* This Scrap aint big enough for the both of us */
  699.  
  700.     charh=RSGetTextSel(vs, gApplicationPrefs->CopyTableThresh);        /* Get the text selection */
  701.  
  702.     if (charh>(char **)0L) {                    /* BYU LSC - Can't do anything without characters */
  703.         HLock(charh);                /* Lock for putting */
  704.         tlong=PutScrap(GetHandleSize(charh),'TEXT',*charh);
  705.                                     /* Put it as a TEXT resource */
  706.         HUnlock(charh);                /* Unlock for disposal */
  707.         DisposHandle(charh);        /* Kill the chars */
  708.         }
  709.     else putln("No characters to copy darn it!");
  710. }
  711.  
  712. /*
  713.  *    paste - Paste the resource from the scrap into the current WIND, if
  714.  *            and only if it is really text
  715.  */
  716.  
  717. void paste( void)
  718. {
  719.     long
  720.         off,                /* offset */
  721.         length;                /* the lenght of what is on the Scrap */
  722.  
  723.     if (screens[scrn].clientflags & PASTE_IN_PROGRESS) {  // One paste at a time, please
  724.         SysBeep(4);
  725.         return;
  726.         }
  727.         
  728.     /* Flush the buffer if necessary */ //CCP fix for linemode
  729.     if (screens[scrn].kblen>0)
  730.     {    
  731.         netpush(screens[scrn].port);
  732.         netwrite( screens[scrn].port, screens[scrn].kbbuf,
  733.                     screens[scrn].kblen);    
  734.         screens[scrn].kblen=0;
  735.     }
  736.  
  737.     if (GetScrap(0L, 'TEXT', &off)<=0L)        /* If there are no TEXT res's */
  738.             return;                        /* then we can't paste it */
  739.  
  740.     screens[scrn].outhand=myNewHandle(0L);    /* create a handle to put chars in */
  741.  
  742.     length= GetScrap( screens[scrn].outhand, 'TEXT',&off);
  743.                                             /* Store the scrap into the handle */
  744.     screens[scrn].outlen = length;            /* Set the length */
  745.     HLock(screens[scrn].outhand);            /* Lock the Handle down for safety */
  746.     screens[scrn].outptr=*screens[scrn].outhand;    /* Set the pointer */
  747.  
  748.     screens[scrn].clientflags |= PASTE_IN_PROGRESS;
  749.     screens[scrn].incount = 0;
  750.     screens[scrn].outcount = 0;
  751.     
  752.     trbuf_mac_nat((unsigned char *)screens[scrn].outptr,screens[scrn].outlen, screens[scrn].national);    /* LU: translate to national chars */
  753.  
  754.     pasteText( scrn);    /* BYU LSC - routine to paste to net, w/echo if neccessary */
  755. }
  756.  
  757. void displayStatus(short n)
  758. {
  759.     DialogPtr        dptr;
  760.     short            item;
  761.     Str255            scratchPstring,anotherString;
  762.     
  763.     SetCursor(theCursors[normcurs]);
  764.     
  765.     switch(screens[n].active) {
  766.         case CNXN_ISCORPSE:
  767.             GetWTitle(screens[n].wind, scratchPstring);
  768.             GetIndString(anotherString,MISC_STRINGS,AWAITING_DISMISSAL_STRING);
  769.             ParamText( scratchPstring, anotherString, NULL, NULL);
  770.             break;
  771.         case CNXN_OPENING:
  772.             GetIndString(anotherString,MISC_STRINGS,BEING_OPENED_STRING);
  773.             ParamText( screens[n].machine,anotherString, NULL, NULL);
  774.             break;
  775.         default:
  776.             GetIndString(anotherString,MISC_STRINGS,BEING_LOOKED_UP);
  777.             ParamText( screens[n].machine,anotherString, NULL, NULL);
  778.         }
  779.  
  780.     dptr = GetNewMyDialog( StatusDLOG, NULL, kInFront, (void *)ThirdCenterDialog);
  781.  
  782.     item = DLOGCancel+1;
  783.     while (item > DLOGCancel)
  784.         ModalDialog(DLOGwOK_CancelUPP, &item);
  785.  
  786.     updateCursor(1);
  787.     
  788.     if (item == DLOGCancel) {
  789.         netclose(screens[n].port);
  790.         destroyport( n);
  791.         }    
  792.  
  793.     DisposDialog(dptr);
  794. }
  795.  
  796. /*
  797.  *    changeport - handle the menu updates for changing from one port to another
  798.  */
  799. void changeport(short oldprt, short newprt)
  800. {
  801.  
  802.     //sprintf(tempspot,"oldscrn: %d, newscrn: %d",oldprt,newprt); putln(tempspot);
  803.     
  804.     if (screens[oldprt].active == CNXN_ACTIVE) 
  805.         CheckItem(myMenus[Conn], oldprt + FIRST_CNXN_ITEM, FALSE);        /* Adjust Conn menu */
  806.     CheckItem(myMenus[Conn], newprt + FIRST_CNXN_ITEM, TRUE);
  807.  
  808.     CheckItem(myMenus[Emul], EMbs,FALSE);                        /* Adjust BS */
  809.     CheckItem(myMenus[Emul], EMdel,FALSE);
  810.     CheckItem(myMenus[Emul], EMbs+screens[newprt].bsdel,TRUE);    /* and DEL */
  811.  
  812.     if (screens[newprt].tektype < 0) {    // TEK is inhibited
  813.         DisableItem(myMenus[Emul],EMclear);
  814.         DisableItem(myMenus[Emul],EMpage);
  815.         }
  816.     else {
  817.         EnableItem(myMenus[Emul],EMclear);
  818.         EnableItem(myMenus[Emul],EMpage);
  819.     
  820.         if (screens[newprt].tekclear)                /* BYU 2.4.8 */
  821.             CheckItem(myMenus[Emul],EMclear,TRUE);    /* BYU 2.4.8 */
  822.         else                                         /* BYU 2.4.8 */
  823.             CheckItem(myMenus[Emul],EMclear,FALSE);    /* BYU 2.4.8 */
  824.         }
  825.         
  826.     if (screens[newprt].ESscroll)
  827.         CheckItem(myMenus[Emul],EMscroll,TRUE);
  828.     else 
  829.         CheckItem(myMenus[Emul],EMscroll,FALSE);
  830.  
  831.     if (screens[newprt].echo)                     /* LOCAL ECHO */
  832.         CheckItem(myMenus[Emul],EMecho,TRUE);
  833.     else                                         /* REMOTE ECHO */
  834.         CheckItem(myMenus[Emul],EMecho,FALSE);
  835.         
  836.     if (screens[newprt].wrap)                     /* wrap on */
  837.         CheckItem(myMenus[Emul],EMwrap,TRUE);
  838.     else                                         /* wrap off */
  839.         CheckItem(myMenus[Emul],EMwrap,FALSE);
  840.  
  841.     if (VSiscapturing(screens[newprt].vs))                /* BYU 2.4.18 */
  842.         CheckItem(myMenus[Emul], EMcapture,TRUE);        /* BYU 2.4.18 */
  843.     else                                                /* BYU 2.4.18 */
  844.         CheckItem(myMenus[Emul], EMcapture,FALSE);        /* BYU 2.4.18 */
  845.  
  846.     if (screens[newprt].arrowmap)                        /* JMB */
  847.         CheckItem(myMenus[Emul],EMarrowmap, TRUE);        /* JMB */
  848.     else                                                /* JMB */
  849.         CheckItem(myMenus[Emul],EMarrowmap, FALSE);        /* JMB */
  850.         
  851.     if (screens[newprt].pgupdwn)                        /* JMB */
  852.         CheckItem(myMenus[Emul],EMpgupdwn, TRUE);        /* JMB */
  853.     else                                                /* JMB */
  854.         CheckItem(myMenus[Emul],EMpgupdwn, FALSE);        /* JMB */
  855.     
  856.     scrn=newprt;
  857.  
  858.     CheckFonts();
  859.  
  860.     CheckNational(screens[newprt].national);
  861. }
  862.  
  863. // Returns TRUE if the user cancelled the quit
  864. Boolean    HandleQuit(void)
  865. {
  866.     short    i;
  867.     Boolean liveConnections = FALSE, die = TRUE;
  868.     
  869.     if (TelInfo->numwindows>0) 
  870.     {
  871.         for(i = 0; i < MaxSess; i++)
  872.         {
  873.             if ((screens[i].active == CNXN_ACTIVE)||(screens[i].active == CNXN_OPENING))
  874.                 liveConnections = TRUE;
  875.         }
  876.         if (liveConnections)
  877.             die = AskUserAlert(REALLY_QUIT_QUESTION, FALSE);
  878.         
  879.         if (die) 
  880.         {
  881.             for (i = TelInfo->numwindows - 1; i >= 0; i--) 
  882.             {
  883.                 netclose(screens[i].port);
  884.                 destroyport(i);
  885.             }
  886.         }
  887.         else
  888.             return (TRUE);
  889.      }
  890.     if (gApplicationPrefs->destroyKTickets)
  891.         DestroyTickets();
  892.     quit();
  893.     return (FALSE);
  894. }
  895.  
  896. /*
  897.  *    HandleMenuCommand - preform a command denoted by the arguments.
  898.  *        mResult - the result of the menu event
  899.  *        modifiers- modifiers from the menu event
  900.  */
  901.  
  902. void HandleMenuCommand( long mResult, short modifiers)
  903. {
  904.     register short i;
  905.     short theItem, theMenu;
  906.     Boolean doWrap;
  907.  
  908.     theMenu = mResult >> 16;
  909.     theItem = mResult & 0xffff;
  910.     switch(theMenu) {
  911.     case appleMenu:
  912.         if (theItem==1)                /* About Dialog */
  913.             applAbout();
  914.         else
  915.           {
  916.             Str255
  917.                 name;
  918.             GetItem(myMenus[0], theItem, name);        /* Desk accessory */
  919.             OpenDeskAcc(name);
  920.           }
  921.         break;
  922.  
  923.     case fileMenu:
  924.     case NfileMenu:
  925.         switch(theItem) {            
  926.             
  927.         case FLopen:
  928.             PresentOpenConnectionDialog();                    /* Open a connection */                
  929.             break;
  930.  
  931.         case FLclose:                                    /* Close a connection */
  932.             if (!(modifiers &  optionKey))
  933.                 CloseAWindow(FrontWindow());
  934.             else
  935.             {
  936.                 Boolean die = TRUE;
  937.                 if (numberLiveConnections())
  938.                     die = AskUserAlert(CLOSE_ALL_WINDOWS_Q, FALSE);
  939.                 
  940.                 if (die) 
  941.                 {
  942.                     for (i = TelInfo->numwindows - 1; i >= 0; i--) 
  943.                     {
  944.                         netclose(screens[i].port);
  945.                         destroyport(i);
  946.                     }
  947.                 }
  948.                 else
  949.                     break;
  950.             }
  951.             break;
  952.  
  953.         case FLload:                                /* Load a set */
  954.             LoadSet();
  955.             break;
  956.         case FLsave:                                /* Save a set */
  957.             if (TelInfo->numwindows<1) break;
  958.             SaveSet();
  959.             break;
  960.         case FLbin:                                    /* Toggle MacBinary on/off */
  961.             TelInfo->MacBinary = !TelInfo->MacBinary;
  962.             if (TelInfo->MacBinary) {
  963.                 CheckItem(myMenus[Fil], FLbin,TRUE);
  964.                 }
  965.             else {
  966.                 CheckItem(myMenus[Fil], FLbin,FALSE);
  967.                 }
  968.             break;
  969.  
  970.         case FLlog:                                        /* Toggle FTP window on/off*/
  971.             TelInfo->ftplogon=!TelInfo->ftplogon;
  972.             if(TelInfo->ftplogon) {
  973.                 CheckItem(myMenus[Fil],FLlog,TRUE);
  974.                 RSshow(ftplog->vs);
  975.                 SelectWindow(ftplog->wind);
  976.                 }
  977.             else {
  978.                 CheckItem(myMenus[Fil],FLlog,FALSE);
  979.                 RShide(ftplog->vs);
  980.                 }
  981.             break;
  982.  
  983.         case FLprint:                                /* Print Selection (or gr) */
  984.             PrintSelection();
  985.             break;
  986.  
  987.         case FLpset:                                    /* Set up for printer */
  988.             PrintPageSetup();
  989.             break;
  990.  
  991.         case FLquit:
  992.             (void) HandleQuit();
  993.             break;
  994.  
  995.         }
  996.         break;
  997.  
  998.     case editMenu:
  999.     case NeditMenu:
  1000.         if (!SystemEdit(theItem-1)) {                /* Is this mine? */
  1001.             switch(theItem) {
  1002.             case EDcopy:                            /* Copy */
  1003.                 i = MacRGfindwind(FrontWindow());    /* is ICR window? */
  1004.                 if (i >= 0)
  1005.                     MacRGcopy(FrontWindow());        /* copy the ICR window */
  1006.                 else {
  1007.                     i=RGgetdnum(FrontWindow());
  1008.                     if (i>-1)                        /* Copy Graphics */
  1009.                         copyGraph( i);
  1010.                     else                            /* Copy Text */
  1011.                         if ( (i=RSfindvwind(FrontWindow())) >-1)
  1012.                             copyText( i);
  1013.                 }
  1014.                 break;
  1015.  
  1016.             case EDcopyt:                            /* Copy Table */
  1017.                 /* 
  1018.                 *  tech note #180 trick to get MultiFinder to pay attention 
  1019.                 */
  1020.                 if (!SystemEdit(EDcopy-1)) {        /* tell it we did a copy */
  1021.                     i=RGgetdnum(FrontWindow());
  1022.                     if (i>-1)            /* Copy Graphics */
  1023.                         copyGraph( i);
  1024.                     else                /* Copy Text */
  1025.                         if ( (i=RSfindvwind(FrontWindow())) >-1)
  1026.                             copyTable( i);
  1027.                 }
  1028.                 break;
  1029.  
  1030.             case EDpaste:                            /* Paste */
  1031.                 if (TelInfo->numwindows<1)
  1032.                         break;
  1033.                     else paste();            /* Paste if there is a wind to do to*/
  1034.                 break;
  1035.             case EDmacros:                            /* Set them Macros */
  1036.                 Macros();
  1037.                 break;
  1038.             default:
  1039.                 break;
  1040.             }
  1041.         }
  1042.         break;
  1043.  
  1044.     case connMenu:
  1045.     case NconnMenu:
  1046.         if (theItem == COnext) 
  1047.         {
  1048.             if (TelInfo->numwindows >1) 
  1049.             {
  1050.                 short    scratchshort;
  1051.                 if (!(modifiers &  shiftKey)) //go forward
  1052.                 {
  1053.                     scratchshort = WindowPtr2ScreenIndex(FrontWindow()) + 1;
  1054.                     // Skip over inactive connections
  1055.                     while(    (screens[scratchshort].active != CNXN_ACTIVE) &&
  1056.                             (screens[scratchshort].active != CNXN_ISCORPSE) &&
  1057.                             (scratchshort <= TelInfo->numwindows+1))                        
  1058.                         scratchshort++;
  1059.                     if ((scratchshort < 0) || (scratchshort >= TelInfo->numwindows))
  1060.                         scratchshort = 0;
  1061.                 }
  1062.                 else //go backward
  1063.                 {
  1064.                     scratchshort = WindowPtr2ScreenIndex(FrontWindow()) - 1;
  1065.                     // Skip over inactive connections
  1066.                     while(    (screens[scratchshort].active != CNXN_ACTIVE) &&
  1067.                             (screens[scratchshort].active != CNXN_ISCORPSE) &&
  1068.                             (scratchshort >= 0))                        
  1069.                         scratchshort--;
  1070.                     if ((scratchshort < 0) || (scratchshort >= TelInfo->numwindows))
  1071.                         scratchshort = TelInfo->numwindows - 1;
  1072.                 }        
  1073.                 SelectWindow(screens[scratchshort].wind);
  1074.             }
  1075.             break;
  1076.         }
  1077.         
  1078.         if (theItem == COtitle)    {
  1079.             ChangeWindowName(FrontWindow());
  1080.             break;
  1081.             }
  1082.             
  1083.         if (theItem >= FIRST_CNXN_ITEM) {
  1084.             if ((theItem - FIRST_CNXN_ITEM-1)>(TelInfo->numwindows+1)) break;  /* rotten danish */
  1085.             if (screens[theItem - FIRST_CNXN_ITEM].active != CNXN_ACTIVE) {
  1086.                 displayStatus(theItem - FIRST_CNXN_ITEM);    /* Tell them about it..... */
  1087.                 break;
  1088.                 }
  1089.             else {
  1090.                 HiliteWindow(screens[scrn].wind, FALSE);
  1091.                 changeport(scrn,(theItem - FIRST_CNXN_ITEM));
  1092.                 if (!(modifiers &  optionKey)) SelectWindow(screens[scrn].wind);
  1093.                 else HiliteWindow(screens[scrn].wind, TRUE);
  1094.                 }
  1095.             }
  1096.         break;
  1097.  
  1098.     case netMenu:
  1099.     case NnetMenu:
  1100.         switch(theItem) {
  1101.         case NEftp:                                        /* Send FTP command */
  1102.         case NEip:                                        /* Send IP Number */
  1103.             if (TelInfo->numwindows<1) break;
  1104.             {    char tmpout[30];                        /* Basically the same except for */
  1105.                 unsigned char tmp[4];                    /* The ftp -n phrase in NEftp */
  1106.  
  1107.                 if (screens[scrn].echo && (screens[scrn].kblen>0)) {
  1108.                     netwrite( screens[scrn].port, screens[scrn].kbbuf,
  1109.                                 screens[scrn].kblen);/* if not empty send buffer */
  1110.                     screens[scrn].kblen=0;
  1111.                     }
  1112.                 netgetip(tmp);
  1113.                 if (theItem == NEftp) {
  1114.                     if ((gFTPServerPrefs->ServerState == 1) && !(modifiers & shiftKey))
  1115.                         sprintf(tmpout,"ftp -n %d.%d.%d.%d\015\012",tmp[0],tmp[1],tmp[2],tmp[3]);
  1116.                     else
  1117.                         sprintf(tmpout,"ftp %d.%d.%d.%d\015\012",tmp[0],tmp[1],tmp[2],tmp[3]);
  1118.                     }
  1119.                 else
  1120.                     sprintf(tmpout,"%d.%d.%d.%d",tmp[0],tmp[1],tmp[2],tmp[3]);
  1121.                 netwrite(screens[scrn].port,tmpout,strlen(tmpout));
  1122.                 if (screens[scrn].echo)
  1123.                     VSwrite(screens[scrn].vs,tmpout, strlen(tmpout));
  1124.             }
  1125.             break;
  1126.  
  1127.         case NEayt:                                /* Send "Are You There?"*/
  1128.             if (TelInfo->numwindows<1) break;
  1129.             netpush(screens[scrn].port);
  1130.             netwrite(screens[scrn].port, "\377\366",2);
  1131.             break;
  1132.  
  1133.         case NEao:                                /* Send "Abort Output"*/
  1134.             if (TelInfo->numwindows<1) break;
  1135.             netpush(screens[scrn].port);
  1136.             netwrite(screens[scrn].port, "\377\365",2);
  1137.             screens[ scrn].timing = 1;                        /* set emulate to TMwait */
  1138.             netwrite(screens[scrn].port, "\377\375\006",3);        /* send TM */
  1139.             break;
  1140.  
  1141.         case NEinter:                                /* Send "Interrupt Process"*/
  1142.             if (TelInfo->numwindows<1) break;
  1143.             netpush(screens[scrn].port);
  1144.             netwrite(screens[scrn].port, "\377\364",2);
  1145.             screens[ scrn].timing = 1;                        /* set emulate to TMwait */
  1146.             netwrite(screens[scrn].port, "\377\375\006",3);        /* send TM */
  1147.             break;
  1148.  
  1149.         case NEec:                                /* Send "Erase Character"*/
  1150.             if (TelInfo->numwindows<1) break;
  1151.             netpush(screens[scrn].port);
  1152.             netwrite(screens[scrn].port, "\377\367",2);
  1153.             break;
  1154.  
  1155.         case NEel:                                /* Send "Erase Line"*/
  1156.             if (TelInfo->numwindows<1) break;
  1157.             netpush(screens[scrn].port);
  1158.             netwrite(screens[scrn].port, "\377\370",2);
  1159.             break;
  1160.             
  1161.         case NEscroll:                            /* Suspend Network */
  1162.             TelInfo->ScrlLock=!TelInfo->ScrlLock;
  1163.             if (TelInfo->ScrlLock) 
  1164.                 CheckItem(myMenus[Net], NEscroll,TRUE);
  1165.             else 
  1166.                 CheckItem(myMenus[Net], NEscroll,FALSE);
  1167.             break;
  1168.  
  1169.         case NEnet:                                /* Show Network Numbers */
  1170.             showNetNumbers();
  1171.             break;
  1172.  
  1173.         default:
  1174.             break;
  1175.         }
  1176.         break;
  1177.  
  1178.     case termMenu:
  1179.     case NtermMenu:
  1180.         switch(theItem) {
  1181.  
  1182.         case EMbs:                                /* Backspace for backspace  */
  1183.             if (TelInfo->numwindows<1) break;
  1184.             CheckItem(myMenus[Emul], EMbs+screens[scrn].bsdel,FALSE);
  1185.             screens[scrn].bsdel=0;
  1186.             CheckItem(myMenus[Emul], EMbs+screens[scrn].bsdel,TRUE);
  1187.             break;
  1188.         
  1189.         case EMdel:                                /* Delete for backspace */
  1190.             if (TelInfo->numwindows<1) break;
  1191.             CheckItem(myMenus[Emul], EMbs+screens[scrn].bsdel,FALSE);
  1192.             screens[scrn].bsdel=1;
  1193.             CheckItem(myMenus[Emul], EMbs+screens[scrn].bsdel,TRUE);
  1194.             break;
  1195.  
  1196.         case EMecho:                                /* Toggle Local Echo (if poss.) */
  1197.             if (TelInfo->numwindows < 1) break;
  1198.             if (screens[scrn].echo && (screens[scrn].kblen>0)) {
  1199.                 netwrite( screens[scrn].port, screens[scrn].kbbuf,
  1200.                             screens[scrn].kblen);    /* if not empty send buffer */
  1201.                 screens[scrn].kblen=0;
  1202.                 }
  1203.             screens[scrn].echo= !screens[scrn].echo;    /* toggle */
  1204.             if (screens[scrn].echo) {                    /* LOCAL ECHO */
  1205.                 send_dont(screens[scrn].port,1);
  1206.                 CheckItem(myMenus[Emul],EMecho,TRUE);
  1207.                 }
  1208.             else {                                        /* REMOTE ECHO */
  1209.                 send_do(screens[scrn].port,1);
  1210.                 CheckItem(myMenus[Emul],EMecho,FALSE);
  1211.                 }
  1212.             break;
  1213.             
  1214.         case EMwrap:                                /* wrap mode */
  1215.             if (TelInfo->numwindows < 1) break;
  1216.             if (!screens[scrn].wrap) {                /* is off, turn on */
  1217.                 screens[scrn].wrap = 1;
  1218.                 CheckItem( myMenus[Emul],EMwrap, TRUE);
  1219.                 VSwrite(screens[scrn].vs, "\033[?7h",5);    /* kick emulator */
  1220.                 }
  1221.             else {
  1222.                 screens[scrn].wrap = 0;
  1223.                 CheckItem( myMenus[Emul],EMwrap, FALSE);
  1224.                 VSwrite(screens[scrn].vs, "\033[?7l",5);
  1225.                 }
  1226.             break;
  1227.         
  1228.         case EMarrowmap:                                        /* JMB */
  1229.             if (TelInfo->numwindows < 1) break;                    /* JMB */
  1230.             screens[scrn].arrowmap = !screens[scrn].arrowmap;    /* JMB */
  1231.             if (screens[scrn].arrowmap)                            /* JMB */
  1232.                 CheckItem( myMenus[Emul], EMarrowmap, TRUE);    /* JMB */
  1233.             else                                                /* JMB */
  1234.                 CheckItem( myMenus[Emul], EMarrowmap, FALSE);    /* JMB */
  1235.             break;                                                /* JMB */
  1236.             
  1237.         case EMpgupdwn:
  1238.             if (TelInfo->numwindows < 1) break;                    /* JMB */
  1239.             screens[scrn].pgupdwn = !screens[scrn].pgupdwn;        /* JMB */
  1240.             if (screens[scrn].pgupdwn)                            /* JMB */
  1241.                 CheckItem( myMenus[Emul], EMpgupdwn, TRUE);        /* JMB */
  1242.             else                                                /* JMB */
  1243.                 CheckItem( myMenus[Emul], EMpgupdwn, FALSE);    /* JMB */
  1244.             break;                                                /* JMB */
  1245.             
  1246.         case EMscroll:                                        /* Scrollback on CLS */
  1247.             if (TelInfo->numwindows<1) break;
  1248.             screens[scrn].ESscroll = !screens[scrn].ESscroll;
  1249.             VSscrolcontrol( screens[scrn].vs, -1, screens[scrn].ESscroll);
  1250.             if (screens[scrn].ESscroll)
  1251.                 CheckItem(myMenus[Emul],EMscroll, TRUE);
  1252.             else
  1253.                 CheckItem(myMenus[Emul],EMscroll, FALSE);
  1254.             break;
  1255.             
  1256.         case EMpage:                                    /* TEK page command */
  1257.             if (TelInfo->numwindows<1) break;
  1258.             parse( &screens[scrn],  (unsigned char *) "\033\014",2);    /* BYU LSC */
  1259.             break;
  1260.  
  1261.         case EMclear:                                /* BYU 2.4.8 - Clear on TEK page */
  1262.             if (TelInfo->numwindows<1) break;
  1263.             screens[scrn].tekclear = !screens[scrn].tekclear;
  1264.             if (screens[scrn].tekclear)
  1265.                 CheckItem(myMenus[Emul],EMclear, TRUE);
  1266.             else
  1267.                 CheckItem(myMenus[Emul],EMclear, FALSE);
  1268.             break;
  1269.  
  1270.         case EMscreensize:
  1271.             if (TelInfo->numwindows<1) break;        /* NCSA: SB */
  1272.             SetScreenDimensions((short)scrn);        /* NCSA: SB */
  1273.             break;
  1274.  
  1275.         case EMreset:                                    /* Reset Screen */
  1276.             //RESTORE WRAP AFTER THE RESET!!! BUGG
  1277.             if (TelInfo->numwindows<1) break;
  1278.             doWrap = screens[scrn].wrap;
  1279.             VSreset(screens[scrn].vs);                    /* Reset it */
  1280.             screens[scrn].timing=0;
  1281.             if (doWrap)
  1282.                 VSwrite(screens[scrn].vs, "\033[?7h",5);
  1283.             else
  1284.                 CheckItem( myMenus[Emul],EMwrap, FALSE);
  1285.             break;
  1286.         case EMjump:                                    /* Jump Scroll */
  1287.             if (TelInfo->numwindows<1) break;
  1288.             FlushNetwork(scrn);                            /* Flush it */
  1289.             break;
  1290.             
  1291.         case EMsetup:                            /* need dialog to enter new key values */
  1292.             setupkeys();
  1293.             break;
  1294.  
  1295.         case EMcolor:                                        /* Set color */
  1296.             if (TelInfo->numwindows<1) break;
  1297.             if (TelInfo->haveColorQuickDraw)
  1298.                 RScprompt(screens[scrn].vs);    
  1299.             break;
  1300.         case EMAnsiColor:
  1301.             if (TelInfo->haveColorQuickDraw)
  1302.                 AnsiPrompt();
  1303.                 RSUpdatePalette();
  1304.             return;    
  1305.         case EMcapture:                                            /* BYU 2.4.18 - Capture session to file */
  1306.             if (VSiscapturing(screens[scrn].vs)) {                /* BYU 2.4.18 */
  1307.                 CloseCaptureFile(screens[scrn].vs);                /* BYU 2.4.18 */
  1308.             } else {                                            /* BYU 2.4.18 */
  1309.                 if(VSopencapture(scrn, screens[scrn].vs))        /* BYU 2.4.18 */
  1310.                     CheckItem(myMenus[Emul], EMcapture,TRUE);    /* BYU 2.4.18 */
  1311.             }                                                    /* BYU 2.4.18 */
  1312.  
  1313.             break;                                                /* BYU 2.4.18 */
  1314.  
  1315.         default:
  1316.             break;
  1317.         }
  1318.         break;
  1319.     case fontMenu:
  1320.         if (TelInfo->numwindows>0) {
  1321.             short     itemFontNum;
  1322.             Str255     temp;
  1323.             
  1324.             GetItem( myMenus[Font], theItem, temp);
  1325.             GetFNum( temp, &itemFontNum);
  1326.             
  1327.             RSchangefont( screens[scrn].vs, itemFontNum, 0);
  1328.             CheckFonts();
  1329.             }
  1330.         break;
  1331.     case sizeMenu:
  1332.         if (TelInfo->numwindows>0) 
  1333.         {
  1334.             long    itemFontSize;
  1335.             short     currentSize, junk;
  1336.             Str255     temp;
  1337.             short     numOfItems;
  1338.             
  1339.             numOfItems = CountMItems(myMenus[Sizem]);
  1340.             if (numOfItems == theItem) //use picked 'other...'
  1341.             {
  1342.                 RSgetfont(screens[scrn].vs, &junk, ¤tSize);    
  1343.                 itemFontSize = SetOtherFontSize(currentSize);
  1344.             }
  1345.             else
  1346.             {
  1347.                 GetItem( myMenus[Sizem], theItem, temp);    /* JMB 2.6 -- Much safer to do it */
  1348.                 StringToNum(temp, &itemFontSize);        /*                this way! */
  1349.             }
  1350.  
  1351.             RSchangefont( screens[scrn].vs, -1, itemFontSize);
  1352.             CheckFonts();
  1353.         }
  1354.         break;
  1355.     case opspecMenu:                                            // JMB
  1356.         OpenPortSpecial(myMenus[OpSpec], theItem);                // JMB
  1357.         break;                                                    // JMB
  1358.     case prefsMenu:
  1359.         switch(theItem) {
  1360.             case prfGlobal:
  1361.                 Cenviron();
  1362.                 break;
  1363.             case prfFTP:
  1364.                 Cftp();
  1365.                 break;
  1366.             case prfSess:
  1367.                 EditConfigType(SESSIONPREFS_RESTYPE, &EditSession);
  1368.                 CheckOpSpecSubmenu();
  1369.                 break;
  1370.             case prfTerm:
  1371.                 EditConfigType(TERMINALPREFS_RESTYPE, &EditTerminal);
  1372.                 break;
  1373.             case prfFTPUser:
  1374.                 EditConfigType(FTPUSER, &EditFTPUser);
  1375.             }
  1376.         break;
  1377.     case transMenu:
  1378.         if (TelInfo->numwindows>0) {
  1379.             CheckNational(theItem-1);        // Set up the menu
  1380.             transBuffer(screens[scrn].national, theItem-1);    // Translate the scrollback buffer
  1381.             // and redraw the screen
  1382.             VSredraw(screens[scrn].vs,0,0,VSmaxwidth(screens[scrn].vs),VSgetlines(screens[scrn].vs)-1);    /* LU */
  1383.             screens[scrn].national = theItem-1;
  1384.             }
  1385.         break;
  1386.     case keyMenu:
  1387.         KeyMenu(theItem);
  1388.         break;
  1389.     case funcMenu:
  1390.         FuncMenu(theItem);
  1391.         break;
  1392.     default:
  1393.         break;
  1394.     
  1395.     }
  1396.     HiliteMenu(0);
  1397.   } /* HandleMenuCommand */
  1398.  
  1399. //    Take the user's new translation choice and make sure the proper tables exist to do 
  1400. //        the translations.  If there is a problem, return the default translation as the chouce.
  1401. void    CheckNational(short choice)
  1402. {
  1403.     short i;
  1404.             
  1405.     for(i=1; i<=(nNational+1);i++)
  1406.         if ((choice+1) == i)                    /* Check the Current NatLang */
  1407.             CheckItem( myMenus[National], i, TRUE);
  1408.         else
  1409.             CheckItem( myMenus[National], i, FALSE);
  1410.  
  1411. }
  1412.  
  1413. /*
  1414.  *    extractmenu - remove a connection from the menu.
  1415.  */
  1416.  
  1417. void extractmenu(short screen)
  1418. {
  1419.     DelMenuItem(myMenus[Conn], screen + FIRST_CNXN_ITEM);
  1420.     AdjustMenus();
  1421. }
  1422.  
  1423. /*
  1424.  *    addinmenu - add a connection's name to the menu in position pnum. (name is
  1425.  *        an str255 pointed at by temps).
  1426.  */
  1427.  
  1428. void addinmenu( short screen, Str255 temps, char mark)
  1429. {
  1430.     InsMenuItem(myMenus[Conn], "\pDoh", (screen-1) + FIRST_CNXN_ITEM);
  1431.     SetItem(myMenus[Conn], screen + FIRST_CNXN_ITEM, temps);        // Avoid metas
  1432.     SetItemMark( myMenus[Conn], screen + FIRST_CNXN_ITEM, mark);
  1433.     AdjustMenus();
  1434. }
  1435.  
  1436. /*    Set the item mark for <scrn> to opening connection */
  1437. void SetMenuMarkToOpeningForAGivenScreen( short scrn)
  1438. {
  1439.     unsigned char c=0xa5;
  1440.  
  1441.     SetItemMark( myMenus[Conn], scrn + FIRST_CNXN_ITEM, c );
  1442. }
  1443.  
  1444. /*    Set the item mark for <scrn> to opened connection */
  1445. void SetMenuMarkToLiveForAGivenScreen( short scrn)
  1446. {
  1447.     SetItemMark( myMenus[Conn], scrn + FIRST_CNXN_ITEM, noMark);
  1448.     AdjustMenus();
  1449. }
  1450.  
  1451. void DoTheMenuChecks(void)
  1452. {
  1453.     short    active;
  1454.     short    windownum;
  1455.  
  1456.     if (TelInfo->numwindows>0)
  1457.         {
  1458.         EnableItem( myMenus[Conn],0);
  1459.         if (gApplicationPrefs->KeyPadAndFuncMenus) {            /* Baylor */
  1460.             EnableItem(myMenus[Keypad], 0);            /* Baylor */
  1461.             EnableItem(myMenus[Function], 0);        /* Baylor */
  1462.             }
  1463.         DrawMenuBar();
  1464.         }
  1465.  
  1466.     else 
  1467.         {
  1468.         DisableItem(myMenus[Conn],0);
  1469.         if (gApplicationPrefs->KeyPadAndFuncMenus) {            /* Baylor */
  1470.             DisableItem(myMenus[Keypad], 0);        /* Baylor */
  1471.             DisableItem(myMenus[Function], 0);        /* Baylor */
  1472.             }
  1473.         DrawMenuBar();
  1474.         }
  1475.  
  1476.     active =0;
  1477.     
  1478.     for (windownum=0;windownum<TelInfo->numwindows;windownum++)
  1479.         if (screens[windownum].active == CNXN_ACTIVE) active++;
  1480.         
  1481.     if (active<2)    
  1482.         DisableItem(myMenus[Conn],COnext);
  1483.     else EnableItem(myMenus[Conn],COnext);
  1484.  
  1485.     if (!active)
  1486.         {
  1487.         DisableItem(myMenus[Edit],EDpaste);
  1488.         DisableItem(myMenus[Emul],0);
  1489.         DrawMenuBar();
  1490.         }
  1491.     else 
  1492.         {
  1493.         EnableItem(myMenus[Edit],EDpaste);
  1494.         EnableItem( myMenus[Emul],0);
  1495.         DrawMenuBar();
  1496.         }
  1497. }
  1498.  
  1499.  
  1500.  
  1501. /*--------------------------------------------------------------------------*/
  1502. /* SetupMenusForSelection                                                    */
  1503. /* If there is a selection on screen, then let the user copy and print.        */
  1504. /* If not, then, oh well....just disable the menus and forget about it        */
  1505. /* ...and to think that this good stuff USED to be in rsmac.c.                 */
  1506. /* This is called from RSselect after the user clicks in the window, and     */
  1507. /* was moved here for modularity    - SMB                                    */
  1508. /*--------------------------------------------------------------------------*/
  1509. void SetMenusForSelection (short selected)                    /* NCSA: SB */    
  1510. {                                                            /* NCSA: SB */
  1511.     if (!selected)                                            /* NCSA: SB */
  1512.         {                                                    /* NCSA: SB */
  1513.         DisableItem(myMenus[Fil],FLprint);                    /* NCSA: SB */
  1514.         DisableItem(myMenus[Edit],EDcopy);                    /* NCSA: SB */
  1515.         DisableItem(myMenus[Edit],EDcopyt);                    /* NCSA: SB */
  1516.         }                                                    /* NCSA: SB */
  1517.     else                                                     /* NCSA: SB */
  1518.         {                                                    /* NCSA: SB */
  1519.         EnableItem(myMenus[Fil],FLprint);                    /* NCSA: SB */
  1520.         EnableItem(myMenus[Edit],EDcopy);                    /* NCSA: SB */
  1521.         EnableItem(myMenus[Edit],EDcopyt);                    /* NCSA: SB */
  1522.         }                                                    /* NCSA: SB */
  1523. }                                                            /* NCSA: SB */
  1524.  
  1525.  
  1526. long SetOtherFontSize(short currentSize)
  1527. {
  1528.     DialogPtr    dtemp;
  1529.     Str255 currentSizeStr, newSizeStr;
  1530.     long newSize;
  1531.     Boolean GoodValue;
  1532.     short ditem;
  1533.     
  1534.     dtemp=GetNewMyDialog( OtherFontDLOG, NULL, kInFront, (void *)ThirdCenterDialog); 
  1535.     InitCursor();
  1536.  
  1537.     GoodValue = 0;
  1538.     
  1539.     while (!GoodValue)
  1540.     {
  1541.         GoodValue = TRUE;
  1542.         NumToString((long) currentSize, currentSizeStr);
  1543.         SetTEText(dtemp, FontSizeTE, currentSizeStr);
  1544.     
  1545.         ditem = 0;
  1546.         while(ditem != DLOGOk && ditem != DLOGCancel)
  1547.             ModalDialog(DLOGwOK_CancelUPP, &ditem);
  1548.     
  1549.         if (ditem == DLOGCancel) {
  1550.             DisposeDialog( dtemp);
  1551.             return currentSize;
  1552.         }
  1553.     
  1554.         GetTEText(dtemp, FontSizeTE, newSizeStr);
  1555.         StringToNum(newSizeStr, &newSize);
  1556.     
  1557.         if (newSize < 9)
  1558.             GoodValue = FALSE;
  1559.         
  1560.         if (!GoodValue) SysBeep(4);
  1561.     }
  1562.     DisposeDialog( dtemp);
  1563.     
  1564.     return (newSize);
  1565. }
  1566. /*----------------------------------------------------------------------*/
  1567. /* NCSA: SB - SetColumnWidth                                            */
  1568. /*    Allow the user to FINALLY pick how many columns he wants on the     */
  1569. /*    screen.  Set up a dialog box to pick the # of columns, and then        */
  1570. /*    size-up the Telnet screen accordingly.  NOTE: The user still needs    */
  1571. /*     to do a "resize", unless he is using NAWS                            */
  1572. /*----------------------------------------------------------------------*/
  1573. void SetScreenDimensions(short scrn)
  1574. {
  1575.     DialogPtr    dtemp;
  1576.     Str255        ColumnsSTR, LinesSTR;
  1577.     long        columns, lines;
  1578.     short        ditem, notgood;
  1579.     
  1580.     dtemp=GetNewMyDialog( SizeDLOG, NULL, kInFront, (void *)ThirdCenterDialog); 
  1581.     
  1582.     SetCursor(theCursors[normcurs]);
  1583.  
  1584.     notgood = 1;
  1585.     lines = VSgetlines(screens[scrn].vs);
  1586.     columns = VSgetcols(screens[scrn].vs) + 1;
  1587.     
  1588.     while (notgood) {
  1589.         notgood = 0;                                /* Default to good */
  1590.         NumToString(columns, ColumnsSTR);
  1591.         NumToString(lines, LinesSTR);
  1592.         SetTEText(dtemp, ColumnsNumber, ColumnsSTR);
  1593.         SetTEText(dtemp, LinesNumber, LinesSTR);
  1594.         SelIText( dtemp, ColumnsNumber, 0, 32767);
  1595.     
  1596.         ditem = 3;
  1597.         while(ditem>2)
  1598.             ModalDialog(DLOGwOK_CancelUPP, &ditem);
  1599.     
  1600.         if (ditem == DLOGCancel) {
  1601.             DisposeDialog( dtemp);
  1602.             return;
  1603.             }
  1604.         
  1605.         GetTEText(dtemp, ColumnsNumber, ColumnsSTR);
  1606.         StringToNum(ColumnsSTR, &columns);
  1607.         GetTEText(dtemp, LinesNumber, LinesSTR);
  1608.         StringToNum(LinesSTR, &lines);
  1609.         
  1610.         if (columns < 10) {
  1611.             columns = 10;
  1612.             notgood = 1;
  1613.             }
  1614.         else if (columns > 132) {
  1615.             columns = 132;
  1616.             notgood = 1;
  1617.             }
  1618.  
  1619.         if (lines < 10) {
  1620.             lines = 10;
  1621.             notgood = 1;
  1622.             }
  1623.         else if (lines > 200) {
  1624.             lines = 200;
  1625.             notgood = 1;
  1626.             }
  1627.         
  1628.         if (notgood) SysBeep(4);
  1629.     }
  1630.     
  1631.     DisposeDialog( dtemp);
  1632.     if (VSsetlines( screens[scrn].vs, lines) < 0) 
  1633.         OutOfMemory(-4);
  1634.     else
  1635.     {
  1636.         RScalcwsize( screens[scrn].vs, columns);
  1637.         if (screens[scrn].naws)
  1638.             SendNAWSinfo(&screens[scrn], (short)columns, (short)lines);
  1639.      }
  1640.     updateCursor(1);
  1641. }
  1642.  
  1643. void    ChangeWindowName(WindowPtr    theWindow)
  1644. {
  1645.     DialogPtr    dptr;
  1646.     short        itemHit;
  1647.     Str255        theName;
  1648.  
  1649.     if( theWindow != NULL) {
  1650.         InitCursor();
  1651.         dptr = GetNewMySmallDialog(WinTitlDLOG, NULL, kInFront, (void *)ThirdCenterDialog );
  1652.  
  1653.         GetWTitle(theWindow, theName); 
  1654.         SetTEText( dptr, kWinNameTE, theName);
  1655.         SelIText( dptr, kWinNameTE, 0, 250 );
  1656.  
  1657.         itemHit = 0;
  1658.         while(itemHit != DLOGOk && itemHit != DLOGCancel)
  1659.             ModalDialog(DLOGwOK_CancelUPP, &itemHit);
  1660.         
  1661.         if(itemHit == DLOGOk) {
  1662.             GetTEText(dptr, kWinNameTE, theName);
  1663.             set_new_window_name(theName, theWindow);
  1664.             }
  1665.             
  1666.         DisposDialog(dptr);
  1667.         }
  1668. }
  1669.  
  1670. void    set_new_window_name(Str255 theName, WindowPtr theWindow)
  1671. {
  1672.     short    i;
  1673.     
  1674.     if(theName[0]) {
  1675.         i = WindowPtr2ScreenIndex(theWindow);
  1676.         if (i >= 0) {
  1677.             i += FIRST_CNXN_ITEM;
  1678.             SetWTitle(theWindow, theName);
  1679.             SetItem(myMenus[Conn], i, theName);
  1680.             }
  1681.         }
  1682. }
  1683.